/*
 * DinerController.java
 * Copyright (c) 2014, 2019, Kiri. 
 * All rights reserved.
 */
package com.onesalt.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.onesalt.domain.User;
import com.onesalt.service.DinerService;

/**
 * 食客
 *
 * @author kiri
 * @date 2015年3月22日
 * @version 1.0
 */
@RestController
@RequestMapping("/diner")
public class DinerController {

	private final DinerService dinerService;

	@Autowired
	public DinerController(DinerService dinerService) {
		this.dinerService = dinerService;
	}

	public DinerService getDinerService() {
		return dinerService;
	}

	@RequestMapping(value = "/search", method = RequestMethod.GET)
	public Page<User> search(@RequestParam(required = false) String keyword, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size) {
		return getDinerService().findByKeyword(keyword, (page == null || size == null) ? null : new PageRequest(page, size));
	}
}
